import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import Login from './views/Login.vue'
import Welcome from './views/Welcome.vue'
// 用户管理
import Users from './components/user/Users.vue'
// 权限管理
import Rights from './components/power/Rights.vue'
import Roles from './components/power/Roles.vue'
// 商品管理
import Cate from './components/goods/Cate.vue'
import Params from './components/goods/Params.vue'
<<<<<<< HEAD
=======
import List from './components/goods/List.vue'
// 订单管理
import Orders from './components/orders/Orders.vue'

// 数据统计
import Reports from './components/data/Reports.vue'

>>>>>>> goods_params


Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/',redirect:'/home'},
    { path: '/login',name: 'login',component: Login },
    { path: '/home',name: 'home',component: Home ,redirect:'/welcome',
    children:[
      {path:'/welcome',name:'welcome',component:Welcome},
      {path:'/users',name:'users',component:Users},
      {path:'/rights',name:'rights',component:Rights},
      {path:'/roles',name:'roles',component:Roles},
      {path:'/categories',name:'cate',component:Cate},
<<<<<<< HEAD
      {path:'/params',name:'params',component:Params}
=======
      {path:'/params',name:'params',component:Params},
      {path:'/goods',name:'goods',component:List},
      {path:'/orders',name:'orders',component:Orders},
      {path:'/reports',name:'reports',component:Reports},

>>>>>>> goods_params
    ]
  }
  ]
})


router.beforeEach((to ,from,next )=>{

  if(to.path == '/login') return next();

  const token = window.sessionStorage.getItem('token')
// 强制跳转
  if(!token) return next('/login');

  next()

})

export default router